package org.jkuang.qstar.index.core;

import java.util.concurrent.locks.ReentrantReadWriteLock;

import org.jkuang.qstar.commons.jni.CurMap;
import org.jkuang.qstar.index.cmp.IndexObject;
import org.jkuang.qstar.index.cmp.StructComparator;
import org.jkuang.qstar.index.dic.TermsDic;
import org.jkuang.qstar.index.store.DataStruct;

/**
 * 
 * @author jkuang 2012年11月17日
 *
 */
public class QStarIndex {

	private CurMap store;
	private IndexReader reader;
	private IndexWriter writer;
	private ReentrantReadWriteLock rwlock = new ReentrantReadWriteLock(false);
	private DataStruct<IndexObject> indexs = new DataStruct<IndexObject>(new ReentrantReadWriteLock(false),
			new StructComparator(), 0);

	public QStarIndex(boolean ignoreCase, int node_per_page, int node_avg_data) {
		TermsDic termsDic = new TermsDic(ignoreCase);
		this.store = new CurMap(16, node_per_page, node_avg_data);
		this.reader = new IndexReader(rwlock, termsDic, indexs, this.store);
		this.writer = new IndexWriter(rwlock, termsDic, indexs, this.store);
	}

	public IndexReader getReader() {
		return reader;
	}

	public IndexWriter getWriter() {
		return writer;
	}

}
